package com.witmore.skyline.web.controller;

import com.witmore.skyline.web.config.GlobalAccountSession;
import com.witmore.skyline.web.controller.vo.param.ProjectDeviceUsageRankParam;
import com.witmore.skyline.web.controller.vo.result.*;
import com.witmore.skyline.web.service.ProjectService;
import com.witmore.skyline.web.service.DeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.Valid;

import java.util.List;

/**
 * 首页接口
 * Author: 豆子高
 * Date: 2025/2/27 14:26
 */
@RestController
@RequestMapping("api/home/")
public class HomeController {

    @Autowired
    private ProjectService projectService;

    @Autowired
    private DeviceService deviceService;

    /**
     * 首页统计 V2.1
     */
    @GetMapping(value = "statistics", name = "首页统计")
    public ResponseResult<HomeStatisticsVO> statistics() {
        AccountSession accountInfo = GlobalAccountSession.getUserInfo();
        return projectService.getHomeStatistics(accountInfo);
    }



    /**
     * 项目设备使用率排名列表 V2.1
     */
    @GetMapping(value = "projectDeviceUsageRank", name = "项目设备使用率排名列表")
    public ResponseResult<List<ProjectDeviceUsageItemVO>> projectDeviceUsageRank(@Valid ProjectDeviceUsageRankParam param) {
        AccountSession accountInfo = GlobalAccountSession.getUserInfo();
        return projectService.projectDeviceUsageRank(accountInfo, param);
    }

    /**
     * 项目部设备开工率排名列表 V2.1
     */
    @GetMapping(value = "projectStartRateRank", name = "项目部设备开工率排名列表")
    public ResponseResult<List<ProjectStartRateVO>> projectStartRateRank(@Valid ProjectDeviceUsageRankParam param) {
        AccountSession accountInfo = GlobalAccountSession.getUserInfo();
        return projectService.projectStartRateRank(accountInfo, param);
    }

    /**
     * 查询所有设备当月使用率 V2.1
     */
    @GetMapping(value = "deviceMonthlyUsageRate", name = "查询所有设备当月使用率")
    public ResponseResult<List<DeviceMonthlyUsageRateVO>> deviceMonthlyUsageRate(@RequestParam(required = false) String category) {
        AccountSession accountInfo = GlobalAccountSession.getUserInfo();
        return deviceService.deviceMonthlyUsageRate(accountInfo, category);
    }


}
